require 'test/unit'
require 'soul/core'
require 'soul/char'
require 'soul/number'
require 'soul/special'

class SoulTest < Test::Unit::TestCase

  def test_null_parsers
    #assert(Soul::end(''))
    assert(Soul::nothing.parse('!') == false)
  end

  def test_character_parsers
    assert(Soul::alpha.parse('a'))
    assert(Soul::alpha.parse('A'))
    assert(Soul::digit.parse('2'))
    assert(Soul::alnum.parse('1'))
    assert(Soul::alnum.parse('a'))
    assert(Soul::xdigit.parse('d'))
    assert(Soul::xdigit.parse('4'))
    assert(Soul::any.parse('|'))
    assert(Soul::blank.parse(' '))
    assert(Soul::blank.parse("\t"))
    assert(Soul::char('a').parse('a'))
    assert(Soul::char(('a'..'c')).parse('b'))
    assert(Soul::lower.parse('a'))
    assert(Soul::upper.parse('A'))
    assert(Soul::bdigit.parse('1'))
    assert(Soul::bdigit.parse('0'))
  end
  
  def test_unary_operators
    parser = Soul::alpha
    assert((~parser).parse('a') == false)
    assert((!parser).parse(''))
    assert((!parser).parse('abc'))
    assert((+parser).parse('a'))
    assert((+parser).parse('aa'))
    assert((+parser).parse('') == false)
    assert((-parser).parse(''))
    assert((-parser).parse('a'))
    assert((-parser).parse('aa') == false)
  end
  
  def test_rules_sequence
    assert((Soul::alpha >> Soul::alpha).parse('ab'))
    assert((Soul::alpha >> Soul::digit).parse('a0'))
    assert((Soul::alpha >> Soul::digit >> Soul::alpha).parse('a0b'))
    assert((!Soul::alpha >> Soul::digit ).parse('0'))
    assert((+Soul::alpha >> Soul::digit ).parse('aaa0'))
    assert((Soul::alpha || Soul::digit).parse('a'))
    assert((Soul::alpha || Soul::digit).parse('0'))
    assert((Soul::alpha || Soul::digit).parse('a0'))
    
    assert((Soul::alpha >> Soul::eof).parse('a'))
  end
  
=begin
  def test_number_parsers
    assert(Soul::bin.parse('10'))
    assert(Soul::hex.parse('FF'))
    assert(Soul::int.parse('120'))
    assert(Soul::int.parse('-1'))
    assert(Soul::int.parse('0'))
    assert(Soul::oct.parse('77'))
    assert(Soul::real.parse('-10.1'))
    assert(Soul::real.parse('10.1'))
    assert(Soul::real.parse('0.0'))
    assert(Soul::uint.parse('10'))
    assert(Soul::ureal.parse('10.1'))
    assert(Soul::real.parse('10'))
  end
=end
  
end
